package com.azl.common.util.test;

import org.junit.jupiter.api.Test;

import com.iaz.tech.tools.common.utils.DoublyLinkedList;
import com.iaz.tech.tools.common.utils.IChainNodeAble;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class AZChainTestCase {
	@Test
	void AZChainToolsAdd() {
		System.out.println("AZChainToolsAdd-----start");
		DoublyLinkedList<String> chainList = new DoublyLinkedList<String>();
		for( int i = 0; i < 100; i++ ) {
			chainList.addLast("TEST----TUU-addLast:" + i + ";");
		}
		
		IChainNodeAble<String> _cursor =  chainList.first();
		if ( _cursor == null ) {
			System.out.println("NULL ERROR");
			return;
		}
		System.out.println(_cursor.toData());
		while ( chainList.hasCursorNext() ) {
			_cursor = chainList.nextCursor();
			System.out.println(_cursor.toData());
		}//assertEquals(3, 1+1);
		System.out.println("AZChainToolsAdd-----end");
	}
	
	@Test
	void AZChainToolsInsert() {
		System.out.println("AZChainToolsInsert-----start");
		DoublyLinkedList<String> chainList = new DoublyLinkedList<String>();
		for( int i = 0; i < 100; i++ ) {
			chainList.addFirst("TEST----TUU-addfirst:" + i + ";");
		}
		
		IChainNodeAble<String> _cursor =  chainList.first();
		if ( _cursor == null ) {
			System.out.println("NULL ERROR");
			return;
		}
		System.out.println(_cursor.toData());
		while ( chainList.hasCursorNext() ) {
			_cursor = chainList.nextCursor();
			System.out.println(_cursor.toData());
		}//assertEquals(3, 1+1);
		System.out.println("AZChainToolsInsert-----end");
	}
	
	@Test
	void AZChainToolsAppendPost() {
		System.out.println("AZChainToolsAppendPost-----start");
		DoublyLinkedList<String> chainList = new DoublyLinkedList<String>();
		for( int i = 0; i < 100; i++ ) {
			chainList.addFirst("TEST----AZChainToolsAppendPost:" + i + ";");
		}
		
		chainList.add(100, "天涯芳草101");
		chainList.add(100, "天涯芳草102");
		
		
		IChainNodeAble<String> _cursor =  chainList.first();
		if ( _cursor == null ) {
			System.out.println("NULL ERROR");
			return;
		}
		System.out.println(_cursor.toData());
		while ( chainList.hasCursorNext() ) {
			_cursor = chainList.nextCursor();
			System.out.println(_cursor.toData());
		}//assertEquals(3, 1+1);
		System.out.println("AZChainToolsAppendPost-----end");
	}
	
	@Test
	void AZChainToolsget() {
		System.out.println("AZChainToolsget-----start");
		DoublyLinkedList<String> chainList = new DoublyLinkedList<String>();
		for( int i = 0; i < 0; i++ ) {
			chainList.addFirst("TEST----TUU-fisrt-GET:" + i + ";");
		}
		
		int mSize = chainList.size();
		for( int i = 0; i < mSize; i++) {
			System.out.println( chainList.get(i) );
		}
		
		chainList.addLast( "天涯芳草101");
		
		mSize = chainList.size();
		System.out.println("新 Size:" + mSize);
		for( int i = 0; i < mSize; i++) {
			System.out.println( chainList.get(i) );
		}
		System.out.println("AZChainToolsget-----end");
	}
	
	@Test
	void AZChainToolsAppendDelete() {
		System.out.println("AZChainToolsAppendDelete-----start");
		DoublyLinkedList<String> chainList = new DoublyLinkedList<String>();
		for( int i = 0; i < 0; i++ ) {
			chainList.addFirst("TEST----TUU-addfirst:" + i + ";");
		}
		
		chainList.addLast("天涯芳草101");
		
		
		chainList.delete(0);
		
		IChainNodeAble<String> _cursor =  chainList.first();
		if ( _cursor == null ) {
			System.out.println("NULL ERROR");
			return;
		}
		System.out.println(_cursor.toData());
		while ( chainList.hasCursorNext() ) {
			_cursor = chainList.nextCursor();
			System.out.println(_cursor.toData());
		}//assertEquals(3, 1+1);
		System.out.println("AZChainToolsAppendDelete-----end");
	}
	
	@Test
	void AZChainToolsComplex() {
		System.out.println("AZChainToolsComplex-----start");
		DoublyLinkedList<String> chainList = new DoublyLinkedList<String>();
		for( int i = 0; i < 5; i++ ) {
			chainList.addFirst("TEST---Base:" + i + ";");
		}
		
		DoublyLinkedList<String> chainList_next = new DoublyLinkedList<String>();
		for( int i = 0; i < 3; i++ ) {
			chainList_next.addFirst("TES1---AS1:" + i + ";");
		}
		
		DoublyLinkedList<String> chainList_next2 = new DoublyLinkedList<String>();
		for( int i = 0; i < 9; i++ ) {
			chainList_next2.addFirst("TEST2---AS2:" + i + ";");
		}
		
		chainList_next.first();
		
		chainList.insertHeaderChainNode(chainList_next);
		
		chainList.addLast( "天涯芳草102");
		
		DoublyLinkedList<String> chainList_next3 = new DoublyLinkedList<String>();
		for( int i = 0; i < 9; i++ ) {
			chainList_next3.appendTail("TEST3------AS3:" + i + ";"); 
		}
		chainList_next2.insertTailHeaderChainNode(chainList_next3);
		
		chainList.addLast( "天涯芳草103");
		
		chainList.insertTailHeaderChainNode(chainList_next2);
		
		chainList.first();
		
		IChainNodeAble<String> _cursor_index = chainList.nextIndexNode();
		while(_cursor_index != null) {
			System.out.println(_cursor_index.toData());
			_cursor_index = chainList.nextIndexNode();
		}
		 
		System.out.println("AZChainToolsComplex-----end");
	}
	
}
